/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   Module Name          : com.yaodian100.ec.proposeproduct.web.ProposeProductApproveAction
   Module Description   :

   Date Created      : 2010/1/27
   Original Author   : ellen.li
   Team              : yaodian100
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   MODIFICATION HISTORY
   ------------------------------------------------------------------------------
   Date Modified       Modified by       Comments
   ------------------------------------------------------------------------------
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
package com.yaodian100.ec.proposeproduct.web;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.lang.xwork.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
import com.yaodian100.core.admin.entity.Group;
import com.yaodian100.core.admin.entity.Permission;
import com.yaodian100.core.admin.entity.Role;
import com.yaodian100.core.admin.entity.User;
import com.yaodian100.core.admin.service.GroupService;
import com.yaodian100.core.admin.service.UserService;
import com.yaodian100.core.common.dao.impl.CommonCriteria;
import com.yaodian100.core.common.entity.SimplePager;
import com.yaodian100.core.common.exception.CoreException;
import com.yaodian100.core.common.service.DomainService;
import com.yaodian100.core.common.utils.ServerValue;
import com.yaodian100.core.menu.entity.Menu;
import com.yaodian100.ec.category.entity.Category;
import com.yaodian100.ec.category.service.CategoryService;
import com.yaodian100.ec.common.EcConstant;
import com.yaodian100.ec.image.service.ImageService;
import com.yaodian100.ec.product.entity.Brand;
import com.yaodian100.ec.product.entity.Specification;
import com.yaodian100.ec.product.service.ProductService;
import com.yaodian100.ec.proposeproduct.entity.ProposeProduct;
import com.yaodian100.ec.proposeproduct.entity.ProposeProductBatch;
import com.yaodian100.ec.proposeproduct.entity.ProposeSpecification;
import com.yaodian100.ec.proposeproduct.service.ProposeProductBatchService;
import com.yaodian100.ec.proposeproduct.service.ProposeProductService;
import com.yaodian100.ec.proposeproduct.service.ProposeSpecificationService;
import com.yaodian100.ec.supplierapply.entity.SupplierApply;
import com.yaodian100.ec.supplierapply.service.SupplierApplyService;

/**
 * @author ellen.li
 * 
 */
public class ProposeProductApproveAction extends ActionSupport implements Preparable {

	private static final long serialVersionUID = 7161469292047262630L;
	private final Logger logger = LoggerFactory.getLogger(ProposeProductApproveAction.class);
	private ProposeSpecificationService proposeSpecificationService;
	private ProposeProductService proposeProductService;
	private ProductService productService;
	private Specification specification;
	private ProposeProduct proposeProduct;
	private ProposeSpecification proposeSpecification;
	private ProposeProductBatchService proposeProductBatchService;
	private ProposeProductBatch proposeProductBatch;
	private ImageService imageService;
	private SimplePager pager;
	private CommonCriteria crit;
	private List<ProposeProduct> proposeProducts;
	private List<ProposeSpecification> proposeSpecifications;
	private String proposeProductBatchIdParam;
	private String productIdParam;
	private String supplierIdParam;
	private String brandParam;
	private String brandName;
	private String proposeStatus;
	private String[] approvePrdt;
	private String filename = "";
	private String productId;
	private String brief;
	private String description;
	private String details;
	private String orderNotice;
	private UserService userService;
	private GroupService groupService;
	private CategoryService categoryService;
	private String categoryResult;
	private DomainService<Menu> menuService;
	@Resource
	private SupplierApplyService supplierService;
	/* 商品頁面參數 */
	private String name;
	private String type;
	private String virtual;
	private String mainCategory;
	private String cost;
	private String price;
	private String proposeShelfPrice;
	private String brand;
	private String tax;
	private String editleadtime;
	private String delivertolerance;
	private String length;
	private String width;
	private String height;
	private String weight;
	private String volume;
	private String unit;
	private String minpo;
	private String maxpo;
	private String temperature;
	private String returnpickup;
	private String returnable;
	private String editsupplier;
	private String editTwSupplier = "";
	private String editbrand;
	private String pm;
	private String organization;
	private String memo;
	private String[] prdtDelete;
	private String keyword;
	private String editDeliverGeoRange;
	private List<Brand> brands;// 品牌
	private String showSeq;
	private String categoryPath;
	private String categoryId;
	private String jsonCategoryPath;
	private String mainCategoryId;
	private Category category;
	private List<Category> rootCategories;
	private Map<String, String> mapRootCategories;
	private final Map<String, String> mapallsuppliers = new HashMap<String, String>();
	private Collection<SupplierApply> allsupplierapplys;// 所有的供應商
	private List<User> users;
	private Menu freightMenu;
	private Menu expireMenu;
	private Menu specStatusMenu;
	private List<Group> groups;
	private String supplierCompanyName;
	private String twSupplierCompanyName = "";
	private String isScm = "N";
	private String expireManage;
	private String batchAction;
	private String useDeliveryDay = "N";
	private int deliveryDay = 0;
	private String isEndNode = "N";
	/* Spec頁面參數 */
	private String[] spcName;
	private String[] spcId;
	private String[] spcCode;
	private String[] spcBarCode;
	private String[] spcReverseInventory;
	private String[] spcMaxCountPerOrder;
	private String[] spcMinCountPerOrder;
	private String[] spcSafeInventory;
	private String[] spcDelete;
	private String[] specStatus;
	private String graphicType;

	public String aprvProduct() throws Exception {
		if (approvePrdt != null && !StringUtils.isBlank(batchAction)) {
			Map<String, Object> result = new HashMap<String, Object>();
			if ("approve".equals(batchAction)) {
				result = proposeProductService.approveProduct(approvePrdt);
			} else if ("delete".equals(batchAction)) {
				result = proposeProductService.deleteProduct(approvePrdt);
			} else if ("unapprove".equals(batchAction)) {
				result = proposeProductService.unapproveProduct(approvePrdt);
			}

			if (result.containsKey("successNum")) {
				addActionMessage("异动成功数:" + result.get("successNum"));
			}
			if (result.containsKey("failNum")) {
				addActionMessage("异动失败数:" + result.get("failNum"));
			}
			if (result.containsKey("failReason")) {
				addActionMessage("异动失败原因:");
				ArrayList<String> failReason = (ArrayList) result.get("failReason");
				for (int i = 0; i < failReason.size(); i++) {
					addActionMessage(failReason.get(i));
				}
			}
		}
		return list();
	}

	/* 編輯提报商品 */
	public String edit() throws Exception {
		if (StringUtils.isBlank(productId) || StringUtils.length(productId) != 8 || !NumberUtils.isNumber(productId)) {
			addActionError("传入参数错误");
			return list();
		} else {
			if (null != productId) {
				proposeProduct = proposeProductService.get(productId);
			} else {
				proposeProduct = proposeProductService.get(proposeProduct.getId());
			}
			if (null == proposeProduct) {
				addActionError("查无商品资料(或无该权限查看)");
				return list();
			} else {
				setBrief(productService.readFromFile(productId, "brief"));
				setDescription(productService.readFromFile(productId, "description"));
				setDetails(productService.readFromFile(productId, "details"));
				setOrderNotice(productService.readFromFile(productId, "orderNotice"));
				// 加入category为0或是找不到category的判断
				if (0 != proposeProduct.getProposeCategoryId()) {
					Category category = categoryService
							.get(Long.parseLong(String.valueOf(proposeProduct.getProposeCategoryId())));
					if (null != category) {
						categoryPath = category.getCategoryPath();
						isEndNode = category.getIsEndnode();
					}
				}
				setEditsupplier(proposeProduct.getSupplierId());
				setEditbrand(StringUtils.defaultString(proposeProduct.getBrand()));
				if (null != proposeProduct.getBrand() || StringUtils.isNotBlank(proposeProduct.getBrand())) {
					// setBrandParam(proposeProduct.getBrand());
					if (null != productService.getBrandByBrandId(proposeProduct.getBrand())) {
						Brand brand = productService.getBrandByBrandId(proposeProduct.getBrand());
						setBrandName(brand.getBrandName());
					} else {
						setBrandName("");
					}
				} else {
					setBrandName("");
				}
				setPm(proposeProduct.getPmId());
				setEditDeliverGeoRange(proposeProduct.getDeliverGeoRange());
				setExpireManage(proposeProduct.getExpireManage());
				SupplierApply supplierApply = supplierService.get(proposeProduct.getSupplierId());
				if (null != supplierApply) {
					supplierCompanyName = supplierApply.getCompanyName();
				}
				if (StringUtils.isNotBlank(proposeProduct.getTwSupplierId())) {
					setEditTwSupplier(proposeProduct.getTwSupplierId());
					SupplierApply twSupplierApply = supplierService.get(proposeProduct.getTwSupplierId());
					if (null != twSupplierApply) {
						twSupplierCompanyName = twSupplierApply.getCompanyName();
					}
				} else {
					setEditTwSupplier("");
					setTwSupplierCompanyName("");
				}
				setDeliveryDay(proposeProduct.getDeliveryDay());
			}
		}
		return "edit";
	}

	public String findCategoryPath() throws Exception {
		if (StringUtils.isNotBlank(categoryId)) {
			Long tempCategoryId = Long.parseLong(categoryId);
			jsonCategoryPath = categoryService.get(tempCategoryId).getCategoryPath();
		}
		return "jsonFindCategoryPath";
	}

	public Collection<SupplierApply> getAllsupplierapplys() {
		return allsupplierapplys;
	}

	public String[] getApprovePrdt() {
		return approvePrdt;
	}

	public String getBatchAction() {
		return batchAction;
	}

	public String getBrand() {
		return brand;
	}

	public String getBrandName() {
		return brandName;
	}

	public String getBrandParam() {
		return brandParam;
	}

	public List<Brand> getBrands() {
		return brands;
	}

	public String getBrief() {
		return brief;
	}

	public Category getCategory() {
		return category;
	}

	public String getCategoryId() {
		return categoryId;
	}

	public String getCategoryPath() {
		return categoryPath;
	}

	public String getCategoryResult() {
		return categoryResult;
	}

	public CategoryService getCategoryService() {
		return categoryService;
	}

	public String getCost() {
		return cost;
	}

	public String getDelivertolerance() {
		return delivertolerance;
	}

	public String getDescription() {
		return description;
	}

	public String getDetails() {
		return details;
	}

	public String getEditbrand() {
		return editbrand;
	}

	public String getEditDeliverGeoRange() {
		return editDeliverGeoRange;
	}

	public String getEditleadtime() {
		return editleadtime;
	}

	public String getEditsupplier() {
		return editsupplier;
	}

	public String getFilename() {
		return filename;
	}

	public Menu getFreightMenu() {
		return freightMenu;
	}

	public List<Group> getGroups() {
		return groups;
	}

	public GroupService getGroupService() {
		return groupService;
	}

	public String getHeight() {
		return height;
	}

	public ImageService getImageService() {
		return imageService;
	}

	public String getIsScm() {
		return isScm;
	}

	/**
	 * 判断是否为最底层的目录
	 * 
	 * @return
	 * @throws CoreException
	 */
	public String getJsonCategoryData() throws CoreException {
		category = categoryService.get(Long.parseLong(mainCategoryId));
		categoryResult = category.getIsEndnode();
		return "jsonCategoryData";
	}

	public String getJsonCategoryPath() {
		return jsonCategoryPath;
	}

	public String getKeyword() {
		return keyword;
	}

	public String getLength() {
		return length;
	}

	public String getMainCategory() {
		return mainCategory;
	}

	public String getMainCategoryId() {
		return mainCategoryId;
	}

	public Map<String, String> getMapallsuppliers() {
		return mapallsuppliers;
	}

	public Map<String, String> getMapRootCategories() {
		return mapRootCategories;
	}

	public String getMaxpo() {
		return maxpo;
	}

	public String getMemo() {
		return memo;
	}

	public DomainService<Menu> getMenuService() {
		return menuService;
	}

	public String getMinpo() {
		return minpo;
	}

	public String getName() {
		return name;
	}

	public String getOrderNotice() {
		return orderNotice;
	}

	public String getOrganization() {
		return organization;
	}

	public SimplePager getPager() {
		return pager;
	}

	public String getPm() {
		return pm;
	}

	public String[] getPrdtDelete() {
		return prdtDelete;
	}

	public String getPrice() {
		return price;
	}

	public String getProductId() {
		return productId;
	}

	public String getProductIdParam() {
		return productIdParam;
	}

	public ProductService getProductService() {
		return productService;
	}

	public ProposeProduct getProposeProduct() {
		return proposeProduct;
	}

	public ProposeProductBatch getProposeProductBatch() {
		return proposeProductBatch;
	}

	public String getProposeProductBatchIdParam() {
		return proposeProductBatchIdParam;
	}

	public ProposeProductBatchService getProposeProductBatchService() {
		return proposeProductBatchService;
	}

	public List<ProposeProduct> getProposeProducts() {
		return proposeProducts;
	}

	public ProposeProductService getProposeProductService() {
		return proposeProductService;
	}

	public String getProposeShelfPrice() {
		return proposeShelfPrice;
	}

	public ProposeSpecification getProposeSpecification() {
		return proposeSpecification;
	}

	public List<ProposeSpecification> getProposeSpecifications() {
		return proposeSpecifications;
	}

	public ProposeSpecificationService getProposeSpecificationService() {
		return proposeSpecificationService;
	}

	public String getProposeStatus() {
		return proposeStatus;
	}

	public String getReturnable() {
		return returnable;
	}

	public String getReturnpickup() {
		return returnpickup;
	}

	public List<Category> getRootCategories() {
		return rootCategories;
	}

	public String getShowSeq() {
		return showSeq;
	}

	public String[] getSpcBarCode() {
		return spcBarCode;
	}

	public String[] getSpcCode() {
		return spcCode;
	}

	public String[] getSpcDelete() {
		return spcDelete;
	}

	public String[] getSpcId() {
		return spcId;
	}

	public String[] getSpcMaxCountPerOrder() {
		return spcMaxCountPerOrder;
	}

	public String[] getSpcMinCountPerOrder() {
		return spcMinCountPerOrder;
	}

	public String[] getSpcName() {
		return spcName;
	}

	public String[] getSpcReverseInventory() {
		return spcReverseInventory;
	}

	public String[] getSpcSafeInventory() {
		return spcSafeInventory;
	}

	public Specification getSpecification() {
		return specification;
	}

	public String[] getSpecStatus() {
		return specStatus;
	}

	public Menu getSpecStatusMenu() {
		return specStatusMenu;
	}

	public String getSupplierCompanyName() {
		return supplierCompanyName;
	}

	public String getSupplierIdParam() {
		return supplierIdParam;
	}

	public String getTax() {
		return tax;
	}

	public String getTemperature() {
		return temperature;
	}

	public String getType() {
		return type;
	}

	public String getUnit() {
		return unit;
	}

	public List<User> getUsers() {
		return users;
	}

	public UserService getUserService() {
		return userService;
	}

	public String getVirtual() {
		return virtual;
	}

	public String getVolume() {
		return volume;
	}

	public String getWeight() {
		return weight;
	}

	public String getWidth() {
		return width;
	}

	public String list() throws Exception {
		crit = new CommonCriteria();
		if (StringUtils.isNotBlank(proposeProductBatchIdParam)) {
			crit.addEq("proposeProductBatchId", proposeProductBatchIdParam);
			setProposeProductBatchIdParam(proposeProductBatchIdParam);
		} else {
			setProposeProductBatchIdParam("");
		}

		if (StringUtils.isNotBlank(productIdParam)) {
			crit.addEq("id", productIdParam);
			setProductIdParam(productIdParam);
		} else {
			setProductIdParam("");
		}

		if (null != proposeStatus || !proposeStatus.equals("")) {
			if ("X".equals(proposeStatus)) {
				crit.addEq("isDelete", "Y");
			} else if ("0".equals(proposeStatus)) {
				crit.addEq("isDelete", "N");
				crit.addEq("status", Integer.parseInt(proposeStatus));
			} else if ("1".equals(proposeStatus)) {
				crit.addEq("isDelete", "N");
				crit.addEq("status", Integer.parseInt(proposeStatus));
			}
		} else {
			crit.addEq("status", Integer.parseInt("0"));
		}

		if (StringUtils.isNotBlank(supplierIdParam)) {
			crit.addEq("supplierId", supplierIdParam);
			setSupplierIdParam(supplierIdParam);
		} else {
			setSupplierIdParam("");
		}
		if (StringUtils.isNotBlank(brandParam)) {
			crit.addEq("brand", brandParam);
			setBrandParam(brandParam);
		}
		// else {
		// setBrandParam("");
		// }
		int entitySize = proposeProductService.getListSize(crit).intValue();
		pager.setTotalSize(entitySize);
		proposeProducts = proposeProductService.getList(pager.getCurrentPage() * pager.getPageRecord(), pager
				.getPageRecord(), crit, null);

		setProposeStatus(proposeStatus);

		return "list";
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.opensymphony.xwork2.Preparable#prepare()
	 */
	public void prepare() throws Exception {
		clearErrorsAndMessages();
		filename = ServerValue.getMidProdHtmlPath();
		if (pager == null) {
			pager = new SimplePager();
		}
		pager.setPageRecord(20);// defaut 20
		rootCategories = categoryService.getChild(0l);
		mapRootCategories = new HashMap<String, String>();
		for (Category rootCategory : rootCategories) {
			mapRootCategories.put(rootCategory.getId().toString(), rootCategory.getName());
		}
		// 找出所有的供應商
		crit = new CommonCriteria();
		// allsupplierapplys = productService.getSupplierApplyList(0, -1, crit, null);
		allsupplierapplys = supplierService.getAll(0, -1, new String[] { "companyName asc" });
		SupplierApply supplierapply = new SupplierApply();
		Iterator<SupplierApply> iterator = allsupplierapplys.iterator();
		while (iterator.hasNext()) {
			supplierapply = iterator.next();
			mapallsuppliers.put(supplierapply.getSupplierID(), supplierapply.getCompanyName());
		}

		// 找出所有ｐｍ的user
		if (null == users) {
			users = userService.getByPermission(Role.Default.PM.name(), Permission.Type.ROLE);
		}

		// 运送区域
		if (null == freightMenu) {
			freightMenu = menuService.get("Freight.key");
		}

		// 效期管理分类
		if (null == expireMenu) {
			expireMenu = menuService.get("ExpireManage.Attribute");
		}

		// 找出a-20的部門
		groups = groupService.getList(0, -1, new CommonCriteria().addRlike("code", EcConstant.PRODUCT_PM_GROUP_CODE),
				new String[] { "code" });
		setProposeStatus("0");

		// 规格状态
		if (null == specStatusMenu) {
			specStatusMenu = menuService.get("Specification.SpecStatus");
		}

		// brandParam = "";
	}

	/**
	 * 儲存商品資料
	 * 
	 * @return
	 * @throws Exception
	 */
	public String save() throws Exception {
		if (StringUtils.isNotBlank(productId) || null != proposeProduct.getId()) {
			if (null != productId) {
				proposeProduct = proposeProductService.get(productId);
			} else {
				proposeProduct = proposeProductService.get(proposeProduct.getId());
			}
			category = categoryService.get(Long.valueOf(mainCategoryId));
			if (null == category || category.getIsDelete().equalsIgnoreCase("Y")) {
				addActionError("儲存失敗,主分类资料不正确");
				return "edit";
			}
			if (StringUtils.isBlank(category.getRootId())) {
				addActionError("儲存失敗,主分类资料不正确");
				return "edit";
			}

			proposeProduct.setName(name);
			proposeProduct.setType(Integer.valueOf(type));
			proposeProduct.setIsVirtual(virtual);
			proposeProduct.setProposeCategoryId(Integer.valueOf(mainCategoryId));
			proposeProduct.setCost(new BigDecimal(cost).setScale(2, BigDecimal.ROUND_FLOOR));
			proposeProduct.setListPrice(new BigDecimal(price).setScale(1, BigDecimal.ROUND_FLOOR));
			if (StringUtils.isNotBlank(proposeShelfPrice)) {
				proposeProduct.setPrpsShelfPrice(new BigDecimal(proposeShelfPrice).setScale(1, BigDecimal.ROUND_FLOOR));
			} else {
				proposeProduct.setPrpsShelfPrice(new BigDecimal(0).setScale(1, BigDecimal.ROUND_FLOOR));
			}
			proposeProduct.setTaxClass(tax);
			proposeProduct.setLeadTime(Integer.valueOf(editleadtime));
			proposeProduct.setIsDeliverdTolerance(delivertolerance);
			if (StringUtils.isNotBlank(length)) {
				proposeProduct.setLength(new BigDecimal(length).setScale(2, BigDecimal.ROUND_FLOOR));
			} else {
				proposeProduct.setLength(new BigDecimal(0).setScale(2, BigDecimal.ROUND_FLOOR));
			}
			if (StringUtils.isNotBlank(width)) {
				proposeProduct.setWidth(new BigDecimal(width).setScale(2, BigDecimal.ROUND_FLOOR));
			} else {
				proposeProduct.setWidth(new BigDecimal(0).setScale(2, BigDecimal.ROUND_FLOOR));
			}
			if (StringUtils.isNotBlank(height)) {
				proposeProduct.setHeight(new BigDecimal(height).setScale(2, BigDecimal.ROUND_FLOOR));
			} else {
				proposeProduct.setHeight(new BigDecimal(0).setScale(2, BigDecimal.ROUND_FLOOR));
			}
			if (StringUtils.isNotBlank(weight)) {
				proposeProduct.setWeight(new BigDecimal(weight).setScale(2, BigDecimal.ROUND_FLOOR));
			} else {
				proposeProduct.setWeight(new BigDecimal(0).setScale(2, BigDecimal.ROUND_FLOOR));
			}
			BigDecimal volume = proposeProduct.getWeight().multiply(proposeProduct.getHeight()).multiply(
					proposeProduct.getLength());
			proposeProduct.setVolume(volume.setScale(2, BigDecimal.ROUND_FLOOR));

			proposeProduct.setUnit(unit);
			if (!"0".equals(minpo)) {
				proposeProduct.setMinPoQuantity(Integer.valueOf(minpo));
			}
			if (!"0".equals(maxpo)) {
				proposeProduct.setMaxPoQuantity(Integer.valueOf(maxpo));
			}
			if (!"0".equals(temperature)) {
				proposeProduct.setTemperatureType(Integer.valueOf(temperature));
			}

			if (StringUtils.isNotBlank(useDeliveryDay)) {
				proposeProduct.setUseDeliveryDay(useDeliveryDay);
			} else {
				proposeProduct.setUseDeliveryDay("N");
			}
			proposeProduct.setDeliveryDay(deliveryDay);
			proposeProduct.setSupplierId(editsupplier);
			if (Arrays.asList("010000", "010001").contains(editsupplier) && StringUtils.isNotBlank(editTwSupplier)) {
				proposeProduct.setTwSupplierId(editTwSupplier);
			} else {
				proposeProduct.setTwSupplierId("");
			}
			proposeProduct.setBrand(editbrand);
			proposeProduct.setIsReturnPickup(returnpickup);
			proposeProduct.setIsReturnable(returnable);
			proposeProduct.setDeliverGeoRange(editDeliverGeoRange);
			proposeProduct.setExpireManage(expireManage);
			proposeProduct.setIsReturnable(returnable);
			proposeProduct.setPmId(pm);
			proposeProduct.setProductKeyword(keyword);
			proposeProduct.setIsScm(isScm);
			proposeProduct.setGraphicType(graphicType);
			if (StringUtils.isNotBlank(brief)) {
				proposeProduct.setBrief(StringUtils.substring(com.yaodian100.core.common.utils.StringUtils.removeHTML(brief,
						true), 0, 50));
				proposeProductService.saveToFile(productId, brief, "brief");
			}
			if (StringUtils.isNotBlank(description)) {
				proposeProduct.setDescription(StringUtils.substring(com.yaodian100.core.common.utils.StringUtils.removeHTML(
						description, true), 0, 50));
				proposeProductService.saveToFile(productId, description, "description");
			}

			if (StringUtils.isNotBlank(details)) {
				proposeProduct.setDetails(StringUtils.substring(com.yaodian100.core.common.utils.StringUtils.removeHTML(
						details, true), 0, 50));
				proposeProductService.saveToFile(productId, details, "details");
			}

			if (StringUtils.isNotBlank(orderNotice)) {
				proposeProductService.saveToFile(productId, orderNotice, "orderNotice");
			}
		}
		proposeProductService.update(proposeProduct);

		return list();
	}

	/* 新增,删除,修改提报商品Spec */
	public String saveSpec() throws Exception {
		if (spcDelete != null) { // delete spec
			for (int i = 0; i < spcDelete.length; i++) {
				proposeSpecification = proposeSpecificationService.get(Long.parseLong(spcDelete[i]));
				proposeSpecificationService.delete(proposeSpecification);
			}
			spcDelete = null;
		} else {
			for (int i = 0; i < spcName.length; i++) {
				if (spcId[i].equals("")) {// save spec
					proposeSpecification = new ProposeSpecification();
					proposeSpecification.setName(spcName[i]);
					proposeSpecification.setBarCode(spcBarCode[i]);
					proposeSpecification.setSpecCode(spcCode[i]);
					proposeSpecification.setSpecStatus(specStatus[i]);
					if (!spcReverseInventory[i].equals("") || !spcMaxCountPerOrder[i].equals("")
							|| !spcMinCountPerOrder[i].equals("") || !spcSafeInventory[i].equals("")) {
						proposeSpecification.setReverseInventory(Integer.parseInt(spcReverseInventory[i]));
						proposeSpecification.setMaxCountPerOrder(Integer.parseInt(spcMaxCountPerOrder[i]));
						proposeSpecification.setMinCountPerOrder(Integer.parseInt(spcMinCountPerOrder[i]));
						proposeSpecification.setSafeInventory(Integer.parseInt(spcMinCountPerOrder[i]));
						proposeSpecification.setProposeProductId(productId);
						proposeSpecificationService.save(proposeSpecification);
					}
				} else {// update spec
					proposeSpecification = proposeSpecificationService.get(Long.parseLong(spcId[i]));
					proposeSpecification.setName(spcName[i]);
					proposeSpecification.setBarCode(spcBarCode[i]);
					proposeSpecification.setSpecCode(spcCode[i]);
					proposeSpecification.setSpecStatus(specStatus[i]);
					if (!spcReverseInventory[i].equals("") || !spcMaxCountPerOrder[i].equals("")
							|| !spcMinCountPerOrder[i].equals("") || !spcSafeInventory[i].equals("")) {
						proposeSpecification.setReverseInventory(Integer.parseInt(spcReverseInventory[i]));
						proposeSpecification.setMaxCountPerOrder(Integer.parseInt(spcMaxCountPerOrder[i]));
						proposeSpecification.setMinCountPerOrder(Integer.parseInt(spcMinCountPerOrder[i]));
						proposeSpecification.setSafeInventory(Integer.parseInt(spcMinCountPerOrder[i]));
						proposeSpecification.setProposeProductId(productId);
						proposeSpecificationService.save(proposeSpecification);
					}
				}
			}
		}
		return spec();
	}

	public void setAllsupplierapplys(Collection<SupplierApply> allsupplierapplys) {
		this.allsupplierapplys = allsupplierapplys;
	}

	public void setApprovePrdt(String[] approvePrdt) {
		this.approvePrdt = approvePrdt;
	}

	public void setBatchAction(String batchAction) {
		this.batchAction = batchAction;
	}

	public void setBrand(String brand) {
		this.brand = brand;
	}

	public void setBrandName(String brandName) {
		this.brandName = brandName;
	}

	public void setBrandParam(String brandParam) {
		this.brandParam = brandParam;
	}

	public void setBrands(List<Brand> brands) {
		this.brands = brands;
	}

	public void setBrief(String brief) {
		this.brief = brief;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	public void setCategoryId(String categoryId) {
		this.categoryId = categoryId;
	}

	public void setCategoryPath(String categoryPath) {
		this.categoryPath = categoryPath;
	}

	public void setCategoryResult(String categoryResult) {
		this.categoryResult = categoryResult;
	}

	public void setCategoryService(CategoryService categoryService) {
		this.categoryService = categoryService;
	}

	public void setCost(String cost) {
		this.cost = cost;
	}

	public void setDelivertolerance(String delivertolerance) {
		this.delivertolerance = delivertolerance;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setDetails(String details) {
		this.details = details;
	}

	public void setEditbrand(String editbrand) {
		this.editbrand = editbrand;
	}

	public void setEditDeliverGeoRange(String editDeliverGeoRange) {
		this.editDeliverGeoRange = editDeliverGeoRange;
	}

	public void setEditleadtime(String editleadtime) {
		this.editleadtime = editleadtime;
	}

	public void setEditsupplier(String editsupplier) {
		this.editsupplier = editsupplier;
	}

	public void setFilename(String filename) {
		this.filename = filename;
	}

	public void setFreightMenu(Menu freightMenu) {
		this.freightMenu = freightMenu;
	}

	public void setGroups(List<Group> groups) {
		this.groups = groups;
	}

	public void setGroupService(GroupService groupService) {
		this.groupService = groupService;
	}

	public void setHeight(String height) {
		this.height = height;
	}

	public void setImageService(ImageService imageService) {
		this.imageService = imageService;
	}

	public void setIsScm(String isScm) {
		this.isScm = isScm;
	}

	public void setJsonCategoryPath(String jsonCategoryPath) {
		this.jsonCategoryPath = jsonCategoryPath;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}

	public void setLength(String length) {
		this.length = length;
	}

	public void setMainCategory(String mainCategory) {
		this.mainCategory = mainCategory;
	}

	public void setMainCategoryId(String mainCategoryId) {
		this.mainCategoryId = mainCategoryId;
	}

	public void setMapRootCategories(Map<String, String> mapRootCategories) {
		this.mapRootCategories = mapRootCategories;
	}

	public void setMaxpo(String maxpo) {
		this.maxpo = maxpo;
	}

	public void setMemo(String memo) {
		this.memo = memo;
	}

	public void setMenuService(DomainService<Menu> menuService) {
		this.menuService = menuService;
	}

	public void setMinpo(String minpo) {
		this.minpo = minpo;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setOrderNotice(String orderNotice) {
		this.orderNotice = orderNotice;
	}

	public void setOrganization(String organization) {
		this.organization = organization;
	}

	public void setPager(SimplePager pager) {
		this.pager = pager;
	}

	public void setPm(String pm) {
		this.pm = pm;
	}

	public void setPrdtDelete(String[] prdtDelete) {
		this.prdtDelete = prdtDelete;
	}

	public void setPrice(String price) {
		this.price = price;
	}

	public void setProductId(String productId) {
		this.productId = productId;
	}

	public void setProductIdParam(String productIdParam) {
		this.productIdParam = productIdParam;
	}

	public void setProductService(ProductService productService) {
		this.productService = productService;
	}

	public void setProposeProduct(ProposeProduct proposeProduct) {
		this.proposeProduct = proposeProduct;
	}

	public void setProposeProductBatch(ProposeProductBatch proposeProductBatch) {
		this.proposeProductBatch = proposeProductBatch;
	}

	public void setProposeProductBatchIdParam(String proposeProductBatchIdParam) {
		this.proposeProductBatchIdParam = proposeProductBatchIdParam;
	}

	public void setProposeProductBatchService(ProposeProductBatchService proposeProductBatchService) {
		this.proposeProductBatchService = proposeProductBatchService;
	}

	public void setProposeProducts(List<ProposeProduct> proposeProducts) {
		this.proposeProducts = proposeProducts;
	}

	public void setProposeProductService(ProposeProductService proposeProductService) {
		this.proposeProductService = proposeProductService;
	}

	public void setProposeShelfPrice(String proposeShelfPrice) {
		this.proposeShelfPrice = proposeShelfPrice;
	}

	public void setProposeSpecification(ProposeSpecification proposeSpecification) {
		this.proposeSpecification = proposeSpecification;
	}

	public void setProposeSpecifications(List<ProposeSpecification> proposeSpecifications) {
		this.proposeSpecifications = proposeSpecifications;
	}

	public void setProposeSpecificationService(ProposeSpecificationService proposeSpecificationService) {
		this.proposeSpecificationService = proposeSpecificationService;
	}

	public void setProposeStatus(String proposeStatus) {
		this.proposeStatus = proposeStatus;
	}

	public void setReturnable(String returnable) {
		this.returnable = returnable;
	}

	public void setReturnpickup(String returnpickup) {
		this.returnpickup = returnpickup;
	}

	public void setRootCategories(List<Category> rootCategories) {
		this.rootCategories = rootCategories;
	}

	public void setShowSeq(String showSeq) {
		this.showSeq = showSeq;
	}

	public void setSpcBarCode(String[] spcBarCode) {
		this.spcBarCode = spcBarCode;
	}

	public void setSpcCode(String[] spcCode) {
		this.spcCode = spcCode;
	}

	public void setSpcDelete(String[] spcDelete) {
		this.spcDelete = spcDelete;
	}

	public void setSpcId(String[] spcId) {
		this.spcId = spcId;
	}

	public void setSpcMaxCountPerOrder(String[] spcMaxCountPerOrder) {
		this.spcMaxCountPerOrder = spcMaxCountPerOrder;
	}

	public void setSpcMinCountPerOrder(String[] spcMinCountPerOrder) {
		this.spcMinCountPerOrder = spcMinCountPerOrder;
	}

	public void setSpcName(String[] spcName) {
		this.spcName = spcName;
	}

	public void setSpcReverseInventory(String[] spcReverseInventory) {
		this.spcReverseInventory = spcReverseInventory;
	}

	public void setSpcSafeInventory(String[] spcSafeInventory) {
		this.spcSafeInventory = spcSafeInventory;
	}

	public void setSpecification(Specification specification) {
		this.specification = specification;
	}

	public void setSpecStatus(String[] specStatus) {
		this.specStatus = specStatus;
	}

	public void setSpecStatusMenu(Menu specStatusMenu) {
		this.specStatusMenu = specStatusMenu;
	}

	public void setSupplierCompanyName(String supplierCompanyName) {
		this.supplierCompanyName = supplierCompanyName;
	}

	public void setSupplierIdParam(String supplierIdParam) {
		this.supplierIdParam = supplierIdParam;
	}

	public void setTax(String tax) {
		this.tax = tax;
	}

	public void setTemperature(String temperature) {
		this.temperature = temperature;
	}

	public void setType(String type) {
		this.type = type;
	}

	public void setUnit(String unit) {
		this.unit = unit;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public void setVirtual(String virtual) {
		this.virtual = virtual;
	}

	public void setVolume(String volume) {
		this.volume = volume;
	}

	public void setWeight(String weight) {
		this.weight = weight;
	}

	public void setWidth(String width) {
		this.width = width;
	}

	/* 編輯提报商品Spec */
	public String spec() throws Exception {
		crit = new CommonCriteria();
		crit.addEq("proposeProductId", productId);
		String[] sortOrder = new String[] { "modifyDate desc" };
		proposeSpecifications = proposeSpecificationService.getList(0, -1, crit, sortOrder);
		proposeProduct = proposeProductService.get(productId);
		return "spec";
	}

	public String getExpireManage() {
		return expireManage;
	}

	public void setExpireManage(String expireManage) {
		this.expireManage = expireManage;
	}

	public Menu getExpireMenu() {
		return expireMenu;
	}

	public void setExpireMenu(Menu expireMenu) {
		this.expireMenu = expireMenu;
	}

	public String getGraphicType() {
		return graphicType;
	}

	public void setGraphicType(String graphicType) {
		this.graphicType = graphicType;
	}

	public String getEditTwSupplier() {
		return editTwSupplier;
	}

	public String getTwSupplierCompanyName() {
		return twSupplierCompanyName;
	}

	public void setEditTwSupplier(String editTwSupplier) {
		this.editTwSupplier = editTwSupplier;
	}

	public void setTwSupplierCompanyName(String twSupplierCompanyName) {
		this.twSupplierCompanyName = twSupplierCompanyName;
	}

	public String getUseDeliveryDay() {
		return useDeliveryDay;
	}

	public int getDeliveryDay() {
		return deliveryDay;
	}

	public void setUseDeliveryDay(String useDeliveryDay) {
		this.useDeliveryDay = useDeliveryDay;
	}

	public void setDeliveryDay(int deliveryDay) {
		this.deliveryDay = deliveryDay;
	}

	public String getIsEndNode() {
		return isEndNode;
	}

	public void setIsEndNode(String isEndNode) {
		this.isEndNode = isEndNode;
	}

}
